/**
 * 子弹
 */
class Bullet extends Flyrole {
    private angle: number = 0;
    //0:主角子弹;1:条形子弹;2:圆形子弹
    private type: number;
    constructor(){
        super();
        this.hp = 1;
        this.radius = 1
    }
    public init(_type:number, _angle:number = 0):Bullet {
        super._init_();
        this.speed = (_type ? 1 : -1) * (GameMain.game_level <= 21 ? 5 : 7);
        this.angle = _angle;
        this.type = _type;
        this.camp = _type == 0 ? 0 : 1;
        this.playAciton('fly');
        return this;
    }

    //对多向子弹做特殊处理
    public flyForward():void {
        let t_angle:number = this.angle;
        if(t_angle != 0) {
            let t_speed:number = this.speed;
            this.x += t_speed * Math.cos(t_angle);
            this.y -= t_speed * Math.sin(t_angle);
            if((this.speed < 0 && this.y < 0) || (this.speed > 0 && this.y > Main.s_height)) {
                this.rollbackSelf();
            }
        }else{
            super.flyForward();
        }
    }

    protected rollbackSelf():void {
        super.rollbackSelf();
        this.removeSelf();
        Laya.Pool.recover('bullet', this);
    }

    public playAciton(_action: string):void {
        super.playAciton('bullet'+this.type, _action);
    }

    public attacked():void {
        super.attacked();
        this.rollbackSelf();
    }
}